source("../../lib/som-utils.R")
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
source("../../lib/maps-utils.R")
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
mpr.set_base_path_analysis()
model <- mpr.load_model("som-298.rds.xz")
summary(model)
SOM of size 5x5 with a hexagonal topology and a bubble neighbourhood function.
The number of data layers is 1.
Distance measure(s) used: sumofsquares.
Training data included: 94881 objects.
Mean distance to the closest unit in the map: 0.853.
plot(model, type="changes")
df <- mpr.load_data("datos_mes.csv.xz")
df
summary(df)
id_estacion fecha fecha_cnt tmax
Length:94881 Length:94881 Min. : 1.000 Min. :-53.0
Class :character Class :character 1st Qu.: 4.000 1st Qu.:148.0
Mode :character Mode :character Median : 6.000 Median :198.0
Mean : 6.497 Mean :200.2
3rd Qu.: 9.000 3rd Qu.:255.0
Max. :12.000 Max. :403.0
tmin precip nevada prof_nieve
Min. :-121.00 Min. : 0.00 Min. :0.000000 Min. : 0.000
1st Qu.: 53.00 1st Qu.: 3.00 1st Qu.:0.000000 1st Qu.: 0.000
Median : 98.00 Median : 10.00 Median :0.000000 Median : 0.000
Mean : 98.86 Mean : 16.25 Mean :0.000295 Mean : 0.467
3rd Qu.: 148.00 3rd Qu.: 22.00 3rd Qu.:0.000000 3rd Qu.: 0.000
Max. : 254.00 Max. :422.00 Max. :6.000000 Max. :1834.000
longitud latitud altitud
Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:38.28 1st Qu.: -5.6417 1st Qu.: 42.0
Median :40.82 Median : -3.4500 Median : 247.0
Mean :39.66 Mean : -3.4350 Mean : 418.5
3rd Qu.:42.08 3rd Qu.: 0.4914 3rd Qu.: 656.0
Max. :43.57 Max. : 4.2156 Max. :2535.0
world <- ne_countries(scale = "medium", returnclass = "sf")
spain <- subset(world, admin == "Spain")
plot(model, type="count", shape = "straight", palette.name = mpr.degrade.bleu)
NĂºmero de elementos en cada celda:
nb <- table(model$unit.classif)
print(nb)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
631 2776 3157 4954 1668 4558 2617 3184 4547 6033 4399 1190 6665 2263 5909 5796
17 18 19 20 21 22 23 24 25
4501 4767 4992 1189 3736 4577 5082 1035 4655
ComprobaciĂ³n de nodos vacĂos:
dim_model <- 5*5;
len_nb = length(nb);
empty_nodes <- dim_model != len_nb;
if (empty_nodes) {
print(paste("[Warning] Existen nodos vacĂos: ", len_nb, "/", dim_model))
}
plot(model, type="dist.neighbours", shape = "straight")
model_colnames = c("tmax", "tmin", "precip", "longitud", "latitud", "altitud")
model_ncol = length(model_colnames)
plot(model, shape = "straight")
par(mfrow=c(3,4))
for (j in 1:model_ncol) {
plot(model, type="property", property=getCodes(model,1)[,j],
palette.name=mpr.coolBlueHotRed,
main=model_colnames[j],
cex=0.5, shape = "straight")
}
if (!empty_nodes) {
cor <- apply(getCodes(model,1), 2, mpr.weighted.correlation, w=nb, som=model)
print(cor)
}
tmax tmin precip longitud latitud altitud
[1,] -0.4469758 -0.3846492 -0.1579625 -0.4717705 -0.2495934 0.2167603
[2,] 0.8561397 0.8536229 -0.5704927 -0.5794443 -0.2730459 -0.3050501
RepresentaciĂ³n de cada variable en un mapa de factores:
if (!empty_nodes) {
par(mfrow=c(1,1))
plot(cor[1,], cor[2,], xlim=c(-1,1), ylim=c(-1,1), type="n")
lines(c(-1,1),c(0,0))
lines(c(0,0),c(-1,1))
text(cor[1,], cor[2,], labels=model_colnames, cex=0.75)
symbols(0,0,circles=1,inches=F,add=T)
}
Importancia de cada variable - varianza ponderada por el tamaño de la celda:
if (!empty_nodes) {
sigma2 <- sqrt(apply(getCodes(model,1),2,function(x,effectif)
{m<-sum(effectif*(x-weighted.mean(x,effectif))^2)/(sum(effectif)-1)},
effectif=nb))
print(sort(sigma2,decreasing=T))
}
longitud altitud tmax latitud tmin precip
0.9582347 0.9392197 0.9300770 0.9294257 0.9289085 0.8798952
if (!empty_nodes) {
hac <- mpr.hac(model, nb)
}
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=3)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=3)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.: 3.000 1st Qu.:128.0 1st Qu.: 33.00 1st Qu.: 7.00
Median : 5.000 Median :163.0 Median : 66.00 Median : 16.00
Mean : 6.089 Mean :160.9 Mean : 65.51 Mean : 21.89
3rd Qu.:10.000 3rd Qu.:196.0 3rd Qu.: 96.00 3rd Qu.: 30.00
Max. :12.000 Max. :352.0 Max. : 223.00 Max. :422.00
nevada prof_nieve longitud latitud
Min. :0.00000 Min. : 0.0000 Min. :27.82 Min. :-17.8889
1st Qu.:0.00000 1st Qu.: 0.0000 1st Qu.:39.86 1st Qu.: -5.5975
Median :0.00000 Median : 0.0000 Median :41.42 Median : -3.1742
Mean :0.00047 Mean : 0.7396 Mean :40.93 Mean : -2.7733
3rd Qu.:0.00000 3rd Qu.: 0.0000 3rd Qu.:42.47 3rd Qu.: 0.4731
Max. :6.00000 Max. :1834.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 58.0
Median : 316.0
Mean : 453.8
3rd Qu.: 687.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :168.0 Min. : 54.0 Min. : 0.000 Min. :0
1st Qu.: 6.000 1st Qu.:252.0 1st Qu.:128.0 1st Qu.: 1.000 1st Qu.:0
Median : 7.000 Median :279.0 Median :156.0 Median : 4.000 Median :0
Mean : 7.348 Mean :278.3 Mean :156.1 Mean : 6.661 Mean :0
3rd Qu.: 9.000 3rd Qu.:305.0 3rd Qu.:183.0 3rd Qu.:11.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :43.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-7.8603 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.98 1st Qu.:-4.0492 1st Qu.: 34.0
Median : 0.00000 Median :40.07 Median :-1.4106 Median : 143.0
Mean : 0.00193 Mean :39.74 Mean :-1.7702 Mean : 320.6
3rd Qu.: 0.00000 3rd Qu.:41.42 3rd Qu.: 0.6217 3rd Qu.: 617.0
Max. :35.00000 Max. :43.36 Max. : 4.2156 Max. :1572.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.0 Min. : 0.000 Min. :0
1st Qu.: 4.000 1st Qu.:200.0 1st Qu.:132.0 1st Qu.: 0.000 1st Qu.:0
Median : 7.000 Median :225.0 Median :160.0 Median : 1.000 Median :0
Mean : 6.507 Mean :217.4 Mean :150.6 Mean : 7.059 Mean :0
3rd Qu.: 9.000 3rd Qu.:253.0 3rd Qu.:190.0 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :114.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.50 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03082 Mean :28.37 Mean :-16.05 Mean : 518.6
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=4)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=4)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8 Min. :-58.00 Min. : 49.00 Min. :0
1st Qu.: 3.000 1st Qu.:126 1st Qu.: 58.00 1st Qu.: 61.50 1st Qu.:0
Median : 9.000 Median :147 Median : 77.00 Median : 74.00 Median :0
Mean : 7.046 Mean :151 Mean : 79.87 Mean : 82.04 Mean :0
3rd Qu.:11.000 3rd Qu.:173 3rd Qu.:100.00 3rd Qu.: 92.00 3rd Qu.:0
Max. :12.000 Max. :350 Max. :223.00 Max. :422.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:42.24 1st Qu.: -8.411 1st Qu.: 42.0
Median : 0.0000 Median :42.89 Median : -5.598 Median : 108.0
Mean : 0.6346 Mean :42.23 Mean : -4.912 Mean : 203.8
3rd Qu.: 0.0000 3rd Qu.:43.36 3rd Qu.: -2.039 3rd Qu.: 261.0
Max. :892.0000 Max. :43.57 Max. : 4.216 Max. :2400.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.: 3.000 1st Qu.:128.0 1st Qu.: 31.00 1st Qu.: 6.00
Median : 5.000 Median :164.0 Median : 65.00 Median : 15.00
Mean : 6.031 Mean :161.5 Mean : 64.64 Mean : 18.24
3rd Qu.:10.000 3rd Qu.:197.0 3rd Qu.: 96.00 3rd Qu.: 27.00
Max. :12.000 Max. :352.0 Max. : 221.00 Max. :126.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.000 Min. :35.28 Min. :-8.6494
1st Qu.:0.000000 1st Qu.: 0.000 1st Qu.:39.85 1st Qu.:-5.4981
Median :0.000000 Median : 0.000 Median :41.32 Median :-2.9553
Mean :0.000499 Mean : 0.746 Mean :40.85 Mean :-2.6435
3rd Qu.:0.000000 3rd Qu.: 0.000 3rd Qu.:42.44 3rd Qu.: 0.4914
Max. :6.000000 Max. :1834.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 58.0
Median : 353.0
Mean : 468.9
3rd Qu.: 704.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :168.0 Min. : 54.0 Min. : 0.000 Min. :0
1st Qu.: 6.000 1st Qu.:252.0 1st Qu.:128.0 1st Qu.: 1.000 1st Qu.:0
Median : 7.000 Median :279.0 Median :156.0 Median : 4.000 Median :0
Mean : 7.348 Mean :278.3 Mean :156.1 Mean : 6.661 Mean :0
3rd Qu.: 9.000 3rd Qu.:305.0 3rd Qu.:183.0 3rd Qu.:11.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :43.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-7.8603 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.98 1st Qu.:-4.0492 1st Qu.: 34.0
Median : 0.00000 Median :40.07 Median :-1.4106 Median : 143.0
Mean : 0.00193 Mean :39.74 Mean :-1.7702 Mean : 320.6
3rd Qu.: 0.00000 3rd Qu.:41.42 3rd Qu.: 0.6217 3rd Qu.: 617.0
Max. :35.00000 Max. :43.36 Max. : 4.2156 Max. :1572.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.0 Min. : 0.000 Min. :0
1st Qu.: 4.000 1st Qu.:200.0 1st Qu.:132.0 1st Qu.: 0.000 1st Qu.:0
Median : 7.000 Median :225.0 Median :160.0 Median : 1.000 Median :0
Mean : 6.507 Mean :217.4 Mean :150.6 Mean : 7.059 Mean :0
3rd Qu.: 9.000 3rd Qu.:253.0 3rd Qu.:190.0 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :114.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.50 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03082 Mean :28.37 Mean :-16.05 Mean : 518.6
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=5)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=5)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8 Min. :-58.00 Min. : 49.00 Min. :0
1st Qu.: 3.000 1st Qu.:126 1st Qu.: 58.00 1st Qu.: 61.50 1st Qu.:0
Median : 9.000 Median :147 Median : 77.00 Median : 74.00 Median :0
Mean : 7.046 Mean :151 Mean : 79.87 Mean : 82.04 Mean :0
3rd Qu.:11.000 3rd Qu.:173 3rd Qu.:100.00 3rd Qu.: 92.00 3rd Qu.:0
Max. :12.000 Max. :350 Max. :223.00 Max. :422.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:42.24 1st Qu.: -8.411 1st Qu.: 42.0
Median : 0.0000 Median :42.89 Median : -5.598 Median : 108.0
Mean : 0.6346 Mean :42.23 Mean : -4.912 Mean : 203.8
3rd Qu.: 0.0000 3rd Qu.:43.36 3rd Qu.: -2.039 3rd Qu.: 261.0
Max. :892.0000 Max. :43.57 Max. : 4.216 Max. :2400.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : -4.0 Min. :-110.00 Min. : 0.00
1st Qu.: 3.000 1st Qu.:132.0 1st Qu.: 34.00 1st Qu.: 6.00
Median : 5.000 Median :166.0 Median : 66.00 Median :14.00
Mean : 6.003 Mean :165.3 Mean : 67.14 Mean :17.43
3rd Qu.:10.000 3rd Qu.:199.0 3rd Qu.: 97.00 3rd Qu.:26.00
Max. :12.000 Max. :352.0 Max. : 221.00 Max. :95.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00000 Min. :35.28 Min. :-8.6494
1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:39.49 1st Qu.:-5.5975
Median :0.000000 Median : 0.00000 Median :41.29 Median :-3.4500
Mean :0.000526 Mean : 0.08321 Mean :40.79 Mean :-2.7727
3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:42.38 3rd Qu.: 0.3264
Max. :6.000000 Max. :229.00000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 52.0
Median : 263.0
Mean : 381.3
3rd Qu.: 667.0
Max. :1894.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.00 Min. :-121.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.: 32.00 1st Qu.: -30.00 1st Qu.: 17.00
Median : 7.000 Median : 81.00 Median : 14.00 Median : 29.00
Mean : 6.556 Mean : 89.32 Mean : 17.88 Mean : 33.37
3rd Qu.: 9.000 3rd Qu.:144.00 3rd Qu.: 68.00 3rd Qu.: 46.00
Max. :12.000 Max. :263.00 Max. : 150.00 Max. :126.00
nevada prof_nieve longitud latitud altitud
Min. :0 Min. : 0.0 Min. :40.78 Min. :-4.0103 Min. :1405
1st Qu.:0 1st Qu.: 0.0 1st Qu.:40.78 1st Qu.:-4.0103 1st Qu.:1894
Median :0 Median : 0.0 Median :42.38 Median : 0.8842 Median :2143
Mean :0 Mean : 13.1 Mean :41.94 Mean :-0.2357 Mean :2103
3rd Qu.:0 3rd Qu.: 0.0 3rd Qu.:42.53 3rd Qu.: 1.5242 3rd Qu.:2316
Max. :0 Max. :1834.0 Max. :42.77 Max. : 2.4378 Max. :2535
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :168.0 Min. : 54.0 Min. : 0.000 Min. :0
1st Qu.: 6.000 1st Qu.:252.0 1st Qu.:128.0 1st Qu.: 1.000 1st Qu.:0
Median : 7.000 Median :279.0 Median :156.0 Median : 4.000 Median :0
Mean : 7.348 Mean :278.3 Mean :156.1 Mean : 6.661 Mean :0
3rd Qu.: 9.000 3rd Qu.:305.0 3rd Qu.:183.0 3rd Qu.:11.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :43.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-7.8603 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.98 1st Qu.:-4.0492 1st Qu.: 34.0
Median : 0.00000 Median :40.07 Median :-1.4106 Median : 143.0
Mean : 0.00193 Mean :39.74 Mean :-1.7702 Mean : 320.6
3rd Qu.: 0.00000 3rd Qu.:41.42 3rd Qu.: 0.6217 3rd Qu.: 617.0
Max. :35.00000 Max. :43.36 Max. : 4.2156 Max. :1572.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.0 Min. : 0.000 Min. :0
1st Qu.: 4.000 1st Qu.:200.0 1st Qu.:132.0 1st Qu.: 0.000 1st Qu.:0
Median : 7.000 Median :225.0 Median :160.0 Median : 1.000 Median :0
Mean : 6.507 Mean :217.4 Mean :150.6 Mean : 7.059 Mean :0
3rd Qu.: 9.000 3rd Qu.:253.0 3rd Qu.:190.0 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :114.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.50 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03082 Mean :28.37 Mean :-16.05 Mean : 518.6
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=6)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=6)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8 Min. :-58.00 Min. : 49.00 Min. :0
1st Qu.: 3.000 1st Qu.:126 1st Qu.: 58.00 1st Qu.: 61.50 1st Qu.:0
Median : 9.000 Median :147 Median : 77.00 Median : 74.00 Median :0
Mean : 7.046 Mean :151 Mean : 79.87 Mean : 82.04 Mean :0
3rd Qu.:11.000 3rd Qu.:173 3rd Qu.:100.00 3rd Qu.: 92.00 3rd Qu.:0
Max. :12.000 Max. :350 Max. :223.00 Max. :422.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:42.24 1st Qu.: -8.411 1st Qu.: 42.0
Median : 0.0000 Median :42.89 Median : -5.598 Median : 108.0
Mean : 0.6346 Mean :42.23 Mean : -4.912 Mean : 203.8
3rd Qu.: 0.0000 3rd Qu.:43.36 3rd Qu.: -2.039 3rd Qu.: 261.0
Max. :892.0000 Max. :43.57 Max. : 4.216 Max. :2400.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : -4.0 Min. :-110.00 Min. : 0.00
1st Qu.: 3.000 1st Qu.:132.0 1st Qu.: 34.00 1st Qu.: 6.00
Median : 5.000 Median :166.0 Median : 66.00 Median :14.00
Mean : 6.003 Mean :165.3 Mean : 67.14 Mean :17.43
3rd Qu.:10.000 3rd Qu.:199.0 3rd Qu.: 97.00 3rd Qu.:26.00
Max. :12.000 Max. :352.0 Max. : 221.00 Max. :95.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00000 Min. :35.28 Min. :-8.6494
1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:39.49 1st Qu.:-5.5975
Median :0.000000 Median : 0.00000 Median :41.29 Median :-3.4500
Mean :0.000526 Mean : 0.08321 Mean :40.79 Mean :-2.7727
3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:42.38 3rd Qu.: 0.3264
Max. :6.000000 Max. :229.00000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 52.0
Median : 263.0
Mean : 381.3
3rd Qu.: 667.0
Max. :1894.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.00 Min. :-121.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.: 32.00 1st Qu.: -30.00 1st Qu.: 17.00
Median : 7.000 Median : 81.00 Median : 14.00 Median : 29.00
Mean : 6.556 Mean : 89.32 Mean : 17.88 Mean : 33.37
3rd Qu.: 9.000 3rd Qu.:144.00 3rd Qu.: 68.00 3rd Qu.: 46.00
Max. :12.000 Max. :263.00 Max. : 150.00 Max. :126.00
nevada prof_nieve longitud latitud altitud
Min. :0 Min. : 0.0 Min. :40.78 Min. :-4.0103 Min. :1405
1st Qu.:0 1st Qu.: 0.0 1st Qu.:40.78 1st Qu.:-4.0103 1st Qu.:1894
Median :0 Median : 0.0 Median :42.38 Median : 0.8842 Median :2143
Mean :0 Mean : 13.1 Mean :41.94 Mean :-0.2357 Mean :2103
3rd Qu.:0 3rd Qu.: 0.0 3rd Qu.:42.53 3rd Qu.: 1.5242 3rd Qu.:2316
Max. :0 Max. :1834.0 Max. :42.77 Max. : 2.4378 Max. :2535
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :168.0 Min. : 54.0 Min. : 0.000 Min. :0
1st Qu.: 6.000 1st Qu.:252.0 1st Qu.:128.0 1st Qu.: 1.000 1st Qu.:0
Median : 7.000 Median :279.0 Median :156.0 Median : 4.000 Median :0
Mean : 7.348 Mean :278.3 Mean :156.1 Mean : 6.661 Mean :0
3rd Qu.: 9.000 3rd Qu.:305.0 3rd Qu.:183.0 3rd Qu.:11.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :43.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-7.8603 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.98 1st Qu.:-4.0492 1st Qu.: 34.0
Median : 0.00000 Median :40.07 Median :-1.4106 Median : 143.0
Mean : 0.00193 Mean :39.74 Mean :-1.7702 Mean : 320.6
3rd Qu.: 0.00000 3rd Qu.:41.42 3rd Qu.: 0.6217 3rd Qu.: 617.0
Max. :35.00000 Max. :43.36 Max. : 4.2156 Max. :1572.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.00 Min. : 0.00 Min. :0
1st Qu.: 4.000 1st Qu.: 94.0 1st Qu.: 23.00 1st Qu.: 0.00 1st Qu.:0
Median : 7.000 Median :129.0 Median : 51.00 Median : 3.00 Median :0
Mean : 6.585 Mean :138.4 Mean : 60.83 Mean : 10.29 Mean :0
3rd Qu.:10.000 3rd Qu.:183.0 3rd Qu.: 98.00 3rd Qu.: 13.00 3rd Qu.:0
Max. :12.000 Max. :253.0 Max. :159.00 Max. :114.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :28.31 Min. :-16.5 Min. :2371
1st Qu.: 0.0000 1st Qu.:28.31 1st Qu.:-16.5 1st Qu.:2371
Median : 0.0000 Median :28.31 Median :-16.5 Median :2371
Mean : 0.1766 Mean :28.31 Mean :-16.5 Mean :2371
3rd Qu.: 0.0000 3rd Qu.:28.31 3rd Qu.:-16.5 3rd Qu.:2371
Max. :46.0000 Max. :28.31 Max. :-16.5 Max. :2371
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. : 64.0 Min. : 0.000 Min. :0
1st Qu.: 3.000 1st Qu.:212.0 1st Qu.:150.0 1st Qu.: 0.000 1st Qu.:0
Median : 6.000 Median :233.0 Median :168.0 Median : 1.000 Median :0
Mean : 6.491 Mean :233.9 Mean :169.4 Mean : 6.384 Mean :0
3rd Qu.: 9.000 3rd Qu.:259.0 3rd Qu.:196.0 3rd Qu.: 7.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :112.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.0000000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0.0000000 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0.0000000 Median :28.46 Median :-16.26 Median : 33.0
Mean :0.0003515 Mean :28.38 Mean :-15.96 Mean :131.5
3rd Qu.:0.0000000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :2.0000000 Max. :28.95 Max. :-13.60 Max. :632.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=8)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=8)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. : 99.0 Min. :0
1st Qu.: 3.000 1st Qu.:119.5 1st Qu.: 57.00 1st Qu.:110.0 1st Qu.:0
Median :10.000 Median :141.0 Median : 80.00 Median :121.0 Median :0
Mean : 7.501 Mean :148.0 Mean : 80.85 Mean :132.5 Mean :0
3rd Qu.:11.000 3rd Qu.:171.5 3rd Qu.:104.00 3rd Qu.:142.0 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:41.23 1st Qu.: -8.616 1st Qu.: 33.0
Median : 0.000 Median :42.43 Median : -7.456 Median : 251.0
Mean : 3.046 Mean :41.36 Mean : -5.732 Mean : 320.7
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -2.039 3rd Qu.: 370.0
Max. :892.000 Max. :43.57 Max. : 3.035 Max. :2400.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 57.0 Min. : 1.00 Min. : 49.00 Min. :0
1st Qu.: 3.000 1st Qu.:127.0 1st Qu.: 58.00 1st Qu.: 59.00 1st Qu.:0
Median : 9.000 Median :147.0 Median : 76.00 Median : 68.00 Median :0
Mean : 6.942 Mean :151.7 Mean : 79.65 Mean : 70.58 Mean :0
3rd Qu.:11.000 3rd Qu.:173.0 3rd Qu.: 99.00 3rd Qu.: 80.00 3rd Qu.:0
Max. :12.000 Max. :266.0 Max. :180.00 Max. :104.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.649 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:42.33 1st Qu.:-8.372 1st Qu.: 42.0
Median : 0.00000 Median :43.30 Median :-3.875 Median : 98.0
Mean : 0.08646 Mean :42.43 Mean :-4.726 Mean : 177.2
3rd Qu.: 0.00000 3rd Qu.:43.36 3rd Qu.:-2.039 3rd Qu.: 261.0
Max. :35.00000 Max. :43.57 Max. : 4.216 Max. :1572.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : -4.0 Min. :-110.00 Min. : 0.00
1st Qu.: 2.000 1st Qu.:116.0 1st Qu.: 20.00 1st Qu.: 5.00
Median : 4.000 Median :151.0 Median : 47.00 Median :11.00
Mean : 5.785 Mean :148.5 Mean : 45.33 Mean :14.23
3rd Qu.:11.000 3rd Qu.:180.0 3rd Qu.: 73.00 3rd Qu.:21.00
Max. :12.000 Max. :264.0 Max. : 138.00 Max. :80.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :37.13 Min. :-8.6239
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:40.30 1st Qu.:-3.7881
Median :0.000000 Median : 0.0000 Median :41.11 Median :-1.7869
Mean :0.000813 Mean : 0.1115 Mean :40.94 Mean :-1.5403
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:41.91 3rd Qu.: 0.7106
Max. :6.000000 Max. :229.0000 Max. :43.56 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 176.0
Median : 554.0
Mean : 520.1
3rd Qu.: 779.0
Max. :1894.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.00 Min. :-121.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.: 32.00 1st Qu.: -30.00 1st Qu.: 17.00
Median : 7.000 Median : 81.00 Median : 14.00 Median : 29.00
Mean : 6.556 Mean : 89.32 Mean : 17.88 Mean : 33.37
3rd Qu.: 9.000 3rd Qu.:144.00 3rd Qu.: 68.00 3rd Qu.: 46.00
Max. :12.000 Max. :263.00 Max. : 150.00 Max. :126.00
nevada prof_nieve longitud latitud altitud
Min. :0 Min. : 0.0 Min. :40.78 Min. :-4.0103 Min. :1405
1st Qu.:0 1st Qu.: 0.0 1st Qu.:40.78 1st Qu.:-4.0103 1st Qu.:1894
Median :0 Median : 0.0 Median :42.38 Median : 0.8842 Median :2143
Mean :0 Mean : 13.1 Mean :41.94 Mean :-0.2357 Mean :2103
3rd Qu.:0 3rd Qu.: 0.0 3rd Qu.:42.53 3rd Qu.: 1.5242 3rd Qu.:2316
Max. :0 Max. :1834.0 Max. :42.77 Max. : 2.4378 Max. :2535
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 75.0 Min. : -3.0 Min. : 0.0 Min. :0
1st Qu.: 3.000 1st Qu.:165.0 1st Qu.: 80.0 1st Qu.:10.0 1st Qu.:0
Median : 6.000 Median :196.0 Median :108.0 Median :21.0 Median :0
Mean : 6.401 Mean :196.2 Mean :107.1 Mean :23.3 Mean :0
3rd Qu.:10.000 3rd Qu.:226.0 3rd Qu.:135.0 3rd Qu.:35.0 3rd Qu.:0
Max. :12.000 Max. :352.0 Max. :221.0 Max. :95.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.649 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.18 1st Qu.:-6.909 1st Qu.: 22.0
Median : 0.00000 Median :42.24 Median :-5.642 Median : 58.0
Mean : 0.03149 Mean :40.52 Mean :-5.027 Mean : 127.2
3rd Qu.: 0.00000 3rd Qu.:43.35 3rd Qu.:-3.799 3rd Qu.: 148.0
Max. :40.00000 Max. :43.57 Max. : 4.216 Max. :1405.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :168.0 Min. : 54.0 Min. : 0.000 Min. :0
1st Qu.: 6.000 1st Qu.:252.0 1st Qu.:128.0 1st Qu.: 1.000 1st Qu.:0
Median : 7.000 Median :279.0 Median :156.0 Median : 4.000 Median :0
Mean : 7.348 Mean :278.3 Mean :156.1 Mean : 6.661 Mean :0
3rd Qu.: 9.000 3rd Qu.:305.0 3rd Qu.:183.0 3rd Qu.:11.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :43.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-7.8603 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.98 1st Qu.:-4.0492 1st Qu.: 34.0
Median : 0.00000 Median :40.07 Median :-1.4106 Median : 143.0
Mean : 0.00193 Mean :39.74 Mean :-1.7702 Mean : 320.6
3rd Qu.: 0.00000 3rd Qu.:41.42 3rd Qu.: 0.6217 3rd Qu.: 617.0
Max. :35.00000 Max. :43.36 Max. : 4.2156 Max. :1572.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.00 Min. : 0.00 Min. :0
1st Qu.: 4.000 1st Qu.: 94.0 1st Qu.: 23.00 1st Qu.: 0.00 1st Qu.:0
Median : 7.000 Median :129.0 Median : 51.00 Median : 3.00 Median :0
Mean : 6.585 Mean :138.4 Mean : 60.83 Mean : 10.29 Mean :0
3rd Qu.:10.000 3rd Qu.:183.0 3rd Qu.: 98.00 3rd Qu.: 13.00 3rd Qu.:0
Max. :12.000 Max. :253.0 Max. :159.00 Max. :114.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :28.31 Min. :-16.5 Min. :2371
1st Qu.: 0.0000 1st Qu.:28.31 1st Qu.:-16.5 1st Qu.:2371
Median : 0.0000 Median :28.31 Median :-16.5 Median :2371
Mean : 0.1766 Mean :28.31 Mean :-16.5 Mean :2371
3rd Qu.: 0.0000 3rd Qu.:28.31 3rd Qu.:-16.5 3rd Qu.:2371
Max. :46.0000 Max. :28.31 Max. :-16.5 Max. :2371
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. : 64.0 Min. : 0.000 Min. :0
1st Qu.: 3.000 1st Qu.:212.0 1st Qu.:150.0 1st Qu.: 0.000 1st Qu.:0
Median : 6.000 Median :233.0 Median :168.0 Median : 1.000 Median :0
Mean : 6.491 Mean :233.9 Mean :169.4 Mean : 6.384 Mean :0
3rd Qu.: 9.000 3rd Qu.:259.0 3rd Qu.:196.0 3rd Qu.: 7.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :112.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.0000000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0.0000000 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0.0000000 Median :28.46 Median :-16.26 Median : 33.0
Mean :0.0003515 Mean :28.38 Mean :-15.96 Mean :131.5
3rd Qu.:0.0000000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :2.0000000 Max. :28.95 Max. :-13.60 Max. :632.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=10)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=10)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
df.cluster09 <- subset(df, cluster==9)
df.cluster10 <- subset(df, cluster==10)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster09 <- select(df.cluster09, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster10 <- select(df.cluster10, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. : 99.0 Min. :0
1st Qu.: 3.000 1st Qu.:119.5 1st Qu.: 57.00 1st Qu.:110.0 1st Qu.:0
Median :10.000 Median :141.0 Median : 80.00 Median :121.0 Median :0
Mean : 7.501 Mean :148.0 Mean : 80.85 Mean :132.5 Mean :0
3rd Qu.:11.000 3rd Qu.:171.5 3rd Qu.:104.00 3rd Qu.:142.0 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:41.23 1st Qu.: -8.616 1st Qu.: 33.0
Median : 0.000 Median :42.43 Median : -7.456 Median : 251.0
Mean : 3.046 Mean :41.36 Mean : -5.732 Mean : 320.7
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -2.039 3rd Qu.: 370.0
Max. :892.000 Max. :43.57 Max. : 3.035 Max. :2400.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 57.0 Min. : 1.00 Min. : 49.00 Min. :0
1st Qu.: 3.000 1st Qu.:127.0 1st Qu.: 58.00 1st Qu.: 59.00 1st Qu.:0
Median : 9.000 Median :147.0 Median : 76.00 Median : 68.00 Median :0
Mean : 6.942 Mean :151.7 Mean : 79.65 Mean : 70.58 Mean :0
3rd Qu.:11.000 3rd Qu.:173.0 3rd Qu.: 99.00 3rd Qu.: 80.00 3rd Qu.:0
Max. :12.000 Max. :266.0 Max. :180.00 Max. :104.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.649 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:42.33 1st Qu.:-8.372 1st Qu.: 42.0
Median : 0.00000 Median :43.30 Median :-3.875 Median : 98.0
Mean : 0.08646 Mean :42.43 Mean :-4.726 Mean : 177.2
3rd Qu.: 0.00000 3rd Qu.:43.36 3rd Qu.:-2.039 3rd Qu.: 261.0
Max. :35.00000 Max. :43.57 Max. : 4.216 Max. :1572.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : -4.0 Min. :-110.00 Min. : 0.00
1st Qu.: 2.000 1st Qu.: 95.0 1st Qu.: 1.00 1st Qu.: 5.00
Median : 3.000 Median :117.0 Median : 20.00 Median :11.00
Mean : 5.625 Mean :118.2 Mean : 18.61 Mean :14.75
3rd Qu.:11.000 3rd Qu.:142.0 3rd Qu.: 38.00 3rd Qu.:21.00
Max. :12.000 Max. :250.0 Max. : 105.00 Max. :80.00
nevada prof_nieve longitud latitud
Min. :0.00000 Min. : 0.000 Min. :37.13 Min. :-8.624
1st Qu.:0.00000 1st Qu.: 0.000 1st Qu.:40.38 1st Qu.:-4.699
Median :0.00000 Median : 0.000 Median :40.95 Median :-3.723
Mean :0.00099 Mean : 0.214 Mean :40.94 Mean :-3.332
3rd Qu.:0.00000 3rd Qu.: 0.000 3rd Qu.:41.77 3rd Qu.:-1.885
Max. :6.00000 Max. :229.000 Max. :43.46 Max. : 2.482
altitud
Min. : 4.0
1st Qu.: 617.0
Median : 750.0
Mean : 769.3
3rd Qu.: 916.0
Max. :1894.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.00 Min. :-121.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.: 32.00 1st Qu.: -30.00 1st Qu.: 17.00
Median : 7.000 Median : 81.00 Median : 14.00 Median : 29.00
Mean : 6.556 Mean : 89.32 Mean : 17.88 Mean : 33.37
3rd Qu.: 9.000 3rd Qu.:144.00 3rd Qu.: 68.00 3rd Qu.: 46.00
Max. :12.000 Max. :263.00 Max. : 150.00 Max. :126.00
nevada prof_nieve longitud latitud altitud
Min. :0 Min. : 0.0 Min. :40.78 Min. :-4.0103 Min. :1405
1st Qu.:0 1st Qu.: 0.0 1st Qu.:40.78 1st Qu.:-4.0103 1st Qu.:1894
Median :0 Median : 0.0 Median :42.38 Median : 0.8842 Median :2143
Mean :0 Mean : 13.1 Mean :41.94 Mean :-0.2357 Mean :2103
3rd Qu.:0 3rd Qu.: 0.0 3rd Qu.:42.53 3rd Qu.: 1.5242 3rd Qu.:2316
Max. :0 Max. :1834.0 Max. :42.77 Max. : 2.4378 Max. :2535
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 75 Min. : 4.0 Min. : 0.0 Min. :0
1st Qu.: 5.000 1st Qu.:161 1st Qu.: 83.0 1st Qu.:14.0 1st Qu.:0
Median : 7.000 Median :207 Median :118.0 Median :26.0 Median :0
Mean : 6.796 Mean :200 Mean :113.2 Mean :26.4 Mean :0
3rd Qu.: 9.000 3rd Qu.:233 3rd Qu.:144.0 3rd Qu.:37.0 3rd Qu.:0
Max. :12.000 Max. :352 Max. :221.0 Max. :95.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :37.18 Min. :-8.649 Min. : 1
1st Qu.: 0.00000 1st Qu.:42.33 1st Qu.:-8.372 1st Qu.: 42
Median : 0.00000 Median :43.31 Median :-5.698 Median : 81
Mean : 0.03741 Mean :42.79 Mean :-4.820 Mean : 159
3rd Qu.: 0.00000 3rd Qu.:43.46 3rd Qu.:-2.906 3rd Qu.: 261
Max. :40.00000 Max. :43.57 Max. : 4.216 Max. :1405
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : 8.0 Min. :-44.00 Min. : 0.00
1st Qu.: 3.000 1st Qu.:148.0 1st Qu.: 47.00 1st Qu.: 4.00
Median : 4.000 Median :173.0 Median : 67.00 Median :11.00
Mean : 5.896 Mean :169.6 Mean : 63.94 Mean :13.86
3rd Qu.:10.000 3rd Qu.:194.0 3rd Qu.: 84.00 3rd Qu.:21.00
Max. :12.000 Max. :264.0 Max. :138.00 Max. :66.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00000 Min. :37.13 Min. :-7.4558
1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:39.99 1st Qu.:-1.8631
Median :0.000000 Median : 0.00000 Median :41.31 Median : 0.4731
Mean :0.000689 Mean : 0.04004 Mean :40.94 Mean :-0.2922
3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:41.96 3rd Qu.: 1.4181
Max. :4.000000 Max. :59.00000 Max. :43.56 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 61.0
Median : 252.0
Mean : 346.6
3rd Qu.: 582.0
Max. :1213.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 95.0 Min. : -3.00 Min. : 0.00 Min. :0
1st Qu.: 2.000 1st Qu.:167.5 1st Qu.: 76.00 1st Qu.: 5.00 1st Qu.:0
Median : 4.000 Median :186.0 Median : 98.00 Median :14.00 Median :0
Mean : 5.771 Mean :190.2 Mean : 97.23 Mean :18.34 Mean :0
3rd Qu.:11.000 3rd Qu.:210.0 3rd Qu.:119.00 3rd Qu.:28.00 3rd Qu.:0
Max. :12.000 Max. :305.0 Max. :207.00 Max. :80.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.6494 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:36.50 1st Qu.:-6.2567 1st Qu.: 19.0
Median : 0.00000 Median :36.83 Median :-5.6000 Median : 32.0
Mean : 0.02205 Mean :36.90 Mean :-5.3578 Mean : 76.4
3rd Qu.: 0.00000 3rd Qu.:37.26 3rd Qu.:-4.8458 3rd Qu.: 87.0
Max. :34.00000 Max. :42.43 Max. : 0.7106 Max. :667.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :168.0 Min. : 54.0 Min. : 0.000 Min. :0
1st Qu.: 6.000 1st Qu.:252.0 1st Qu.:128.0 1st Qu.: 1.000 1st Qu.:0
Median : 7.000 Median :279.0 Median :156.0 Median : 4.000 Median :0
Mean : 7.348 Mean :278.3 Mean :156.1 Mean : 6.661 Mean :0
3rd Qu.: 9.000 3rd Qu.:305.0 3rd Qu.:183.0 3rd Qu.:11.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :43.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-7.8603 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.98 1st Qu.:-4.0492 1st Qu.: 34.0
Median : 0.00000 Median :40.07 Median :-1.4106 Median : 143.0
Mean : 0.00193 Mean :39.74 Mean :-1.7702 Mean : 320.6
3rd Qu.: 0.00000 3rd Qu.:41.42 3rd Qu.: 0.6217 3rd Qu.: 617.0
Max. :35.00000 Max. :43.36 Max. : 4.2156 Max. :1572.0
if (!empty_nodes) summary(df.cluster09)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.00 Min. : 0.00 Min. :0
1st Qu.: 4.000 1st Qu.: 94.0 1st Qu.: 23.00 1st Qu.: 0.00 1st Qu.:0
Median : 7.000 Median :129.0 Median : 51.00 Median : 3.00 Median :0
Mean : 6.585 Mean :138.4 Mean : 60.83 Mean : 10.29 Mean :0
3rd Qu.:10.000 3rd Qu.:183.0 3rd Qu.: 98.00 3rd Qu.: 13.00 3rd Qu.:0
Max. :12.000 Max. :253.0 Max. :159.00 Max. :114.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :28.31 Min. :-16.5 Min. :2371
1st Qu.: 0.0000 1st Qu.:28.31 1st Qu.:-16.5 1st Qu.:2371
Median : 0.0000 Median :28.31 Median :-16.5 Median :2371
Mean : 0.1766 Mean :28.31 Mean :-16.5 Mean :2371
3rd Qu.: 0.0000 3rd Qu.:28.31 3rd Qu.:-16.5 3rd Qu.:2371
Max. :46.0000 Max. :28.31 Max. :-16.5 Max. :2371
if (!empty_nodes) summary(df.cluster10)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. : 64.0 Min. : 0.000 Min. :0
1st Qu.: 3.000 1st Qu.:212.0 1st Qu.:150.0 1st Qu.: 0.000 1st Qu.:0
Median : 6.000 Median :233.0 Median :168.0 Median : 1.000 Median :0
Mean : 6.491 Mean :233.9 Mean :169.4 Mean : 6.384 Mean :0
3rd Qu.: 9.000 3rd Qu.:259.0 3rd Qu.:196.0 3rd Qu.: 7.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :112.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.0000000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0.0000000 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0.0000000 Median :28.46 Median :-16.26 Median : 33.0
Mean :0.0003515 Mean :28.38 Mean :-15.96 Mean :131.5
3rd Qu.:0.0000000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :2.0000000 Max. :28.95 Max. :-13.60 Max. :632.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1], dim(df.cluster09)[1], dim(df.cluster10)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08", "cluster09", "cluster10"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.hist(df.cluster09)
if (!empty_nodes) mpr.hist(df.cluster10)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster09)
if (!empty_nodes) mpr.boxplot(df.cluster10)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
df.cluster09.grouped <- mpr.group_by_geo(df.cluster09)
df.cluster10.grouped <- mpr.group_by_geo(df.cluster10)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster09.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster10.grouped)